import json


class Config:
    def __init__(self):
        pass
    track: bool = True

    class ser:
        port: str = "/dev/ttyUSB0"
        rate: int = 115200
        timeout: float = 0.5

    class screen:
        device: str = "/dev/video0"
        width: int = 1920
        height: int = 1080
        KeepAspectRatio: bool = True

    @staticmethod
    def json_load(file):
        with open(file) as f:
            item = json.load(f)
            conf = Config()
            # conf.name = item["name"]
            conf.track = item["track"]
            # conf.record = item["record"]
            conf.ser.port = item["serial"]["port"]
            conf.ser.rate = item["serial"]["rate"]
            conf.ser.timeout = item["serial"]["timeout"]
            conf.screen.device = item["screen"]["device"]
            conf.screen.width = item["screen"]["width"]
            conf.screen.height = item["screen"]["height"]
            conf.screen.KeepAspectRatio = item["screen"]["KeepAspectRatio"]
        return conf
